part of 'widgets.dart';

/// [VanDoc]属性常量
final kVanDocBlack = VanCssKey('--van-doc-black');
final kVanDocWhite = VanCssKey('--van-doc-white');
final kVanDocGray1 = VanCssKey('--van-doc-gray-1');
final kVanDocGray2 = VanCssKey('--van-doc-gray-2');
final kVanDocGray3 = VanCssKey('--van-doc-gray-3');
final kVanDocGray4 = VanCssKey('--van-doc-gray-4');
final kVanDocGray5 = VanCssKey('--van-doc-gray-5');
final kVanDocGray6 = VanCssKey('--van-doc-gray-6');
final kVanDocGray7 = VanCssKey('--van-doc-gray-7');
final kVanDocGray8 = VanCssKey('--van-doc-gray-8');
final kVanDocBlue = VanCssKey('--van-doc-blue');
final kVanDocGreen = VanCssKey('--van-doc-green');
final kVanDocPurple = VanCssKey('--van-doc-purple');
final kVanDocPadding = VanCssKey('--van-doc-padding');
final kVanDocRowMaxWidth = VanCssKey('--van-doc-row-max-width');
final kVanDocNavWidth = VanCssKey('--van-doc-nav-width');
final kVanDocBorderRadius = VanCssKey('--van-doc-border-radius');
final kVanDocSimulatorWidth = VanCssKey('--van-doc-simulator-width');
final kVanDocSimulatorHeight = VanCssKey('--van-doc-simulator-height');
final kVanDocHeaderTopHeight = VanCssKey('--van-doc-header-top-height');
final kVanDocCodeFontFamily = VanCssKey('--van-doc-code-font-family');

final kVanDocTextColor1 = VanCssKey('--van-doc-text-color-1');
final kVanDocTextColor2 = VanCssKey('--van-doc-text-color-2');
final kVanDocTextColor3 = VanCssKey('--van-doc-text-color-3');
final kVanDocTextColor4 = VanCssKey('--van-doc-text-color-4');
final kVanDocLinkColor = VanCssKey('--van-doc-link-color');
final kVanDocBackground = VanCssKey('--van-doc-background');
final kVanDocBackground2 = VanCssKey('--van-doc-background-2');
final kVanDocBackground3 = VanCssKey('--van-doc-background-3');
final kVanDocHeaderBackground = VanCssKey('--van-doc-header-background');
final kVanDocBorderColor = VanCssKey('--van-doc-border-color');
final kVanDocCodeColor = VanCssKey('--van-doc-code-color');
final kVanDocCodeCommentColor = VanCssKey('--van-doc-code-comment-color');
final kVanDocCodeBackground = VanCssKey('--van-doc-code-background');
final kVanDocBlockquoteColor = VanCssKey('--van-doc-blockquote-color');
final kVanDocBlockquoteBackground = VanCssKey('--van-doc-blockquote-background');

/// [VanDoc]主题类
@immutable
class _VanDocTheme extends VanProvider<VanDocThemeData> with VanProvide {
  const _VanDocTheme({super.key, super.provide, required super.child});

  static const _prefix = "--van-doc-";

  static bool support(VanCssKey key) => key.key.startsWith(_prefix);

  static dynamic get<T>(BuildContext context, {required VanCssKey key, T? defaultValue}) {
    final VanDocThemeData docTheme = VanDocTheme.of(context);
    if (kVanDocBlack == key) return docTheme.black.get(context);
    if (kVanDocWhite == key) return docTheme.white.get(context);
    if (kVanDocGray1 == key) return docTheme.gray1.get(context);
    if (kVanDocGray2 == key) return docTheme.gray2.get(context);
    if (kVanDocGray3 == key) return docTheme.gray3.get(context);
    if (kVanDocGray4 == key) return docTheme.gray4.get(context);
    if (kVanDocGray5 == key) return docTheme.gray5.get(context);
    if (kVanDocGray6 == key) return docTheme.gray6.get(context);
    if (kVanDocGray7 == key) return docTheme.gray7.get(context);
    if (kVanDocGray8 == key) return docTheme.gray8.get(context);
    if (kVanDocBlue == key) return docTheme.blue.get(context);
    if (kVanDocGreen == key) return docTheme.green.get(context);
    if (kVanDocPurple == key) return docTheme.purple.get(context);
    if (kVanDocPadding == key) return docTheme.padding.get(context);
    if (kVanDocRowMaxWidth == key) return docTheme.rowMaxWidth.get(context);
    if (kVanDocNavWidth == key) return docTheme.navWidth.get(context);
    if (kVanDocBorderRadius == key) return docTheme.borderRadius.get(context);
    if (kVanDocSimulatorWidth == key) return docTheme.simulatorWidth.get(context);
    if (kVanDocSimulatorHeight == key) return docTheme.simulatorHeight.get(context);
    if (kVanDocHeaderTopHeight == key) return docTheme.headerTopHeight.get(context);
    if (kVanDocCodeFontFamily == key) return docTheme.codeFontFamily.get(context);

    if (kVanDocTextColor1 == key) return docTheme.textColor1.get(context);
    if (kVanDocTextColor2 == key) return docTheme.textColor2.get(context);
    if (kVanDocTextColor3 == key) return docTheme.textColor3.get(context);
    if (kVanDocTextColor4 == key) return docTheme.textColor4.get(context);
    if (kVanDocLinkColor == key) return docTheme.linkColor.get(context);
    if (kVanDocBackground == key) return docTheme.background.get(context);
    if (kVanDocBackground2 == key) return docTheme.background2.get(context);
    if (kVanDocBackground3 == key) return docTheme.background3.get(context);
    if (kVanDocHeaderBackground == key) return docTheme.headerBackground.get(context);
    if (kVanDocBorderColor == key) return docTheme.borderColor.get(context);
    if (kVanDocCodeColor == key) return docTheme.codeColor.get(context);
    if (kVanDocCodeCommentColor == key) return docTheme.codeCommentColor.get(context);
    if (kVanDocCodeBackground == key) return docTheme.codeBackground.get(context);
    if (kVanDocBlockquoteColor == key) return docTheme.blockquoteColor.get(context);
    if (kVanDocBlockquoteBackground == key) return docTheme.blockquoteBackground.get(context);
    return null;
  }
}

/// [VanDoc]主题数据类
@immutable
class VanDocThemeData with VanProvide {
  final Brightness brightness;
  final VanCss<Color> black;
  final VanCss<Color> white;
  final VanCss<Color> gray1;
  final VanCss<Color> gray2;
  final VanCss<Color> gray3;
  final VanCss<Color> gray4;
  final VanCss<Color> gray5;
  final VanCss<Color> gray6;
  final VanCss<Color> gray7;
  final VanCss<Color> gray8;
  final VanCss<Color> blue;
  final VanCss<Color> green;
  final VanCss<Color> purple;
  final VanCss<double> padding;
  final VanCss<double> rowMaxWidth;
  final VanCss<double> navWidth;
  final VanCss<double> borderRadius;
  final VanCss<double> simulatorWidth;
  final VanCss<double> simulatorHeight;
  final VanCss<double> headerTopHeight;
  final VanCss<String> codeFontFamily;
  final VanCss<Color> textColor1;
  final VanCss<Color> textColor2;
  final VanCss<Color> textColor3;
  final VanCss<Color> textColor4;
  final VanCss<Color> linkColor;
  final VanCss<Color> background;
  final VanCss<Color> background2;
  final VanCss<Color> background3;
  final VanCss<Color> headerBackground;
  final VanCss<Color> borderColor;
  final VanCss<Color> codeColor;
  final VanCss<Color> codeCommentColor;
  final VanCss<Color> codeBackground;
  final VanCss<Color> blockquoteColor;
  final VanCss<Color> blockquoteBackground;

  /// 构造器
  const VanDocThemeData.raw({
    required this.brightness,
    required this.black,
    required this.white,
    required this.gray1,
    required this.gray2,
    required this.gray3,
    required this.gray4,
    required this.gray5,
    required this.gray6,
    required this.gray7,
    required this.gray8,
    required this.blue,
    required this.green,
    required this.purple,
    required this.padding,
    required this.rowMaxWidth,
    required this.navWidth,
    required this.borderRadius,
    required this.simulatorWidth,
    required this.simulatorHeight,
    required this.headerTopHeight,
    required this.codeFontFamily,
    required this.textColor1,
    required this.textColor2,
    required this.textColor3,
    required this.textColor4,
    required this.linkColor,
    required this.background,
    required this.background2,
    required this.background3,
    required this.headerBackground,
    required this.borderColor,
    required this.codeColor,
    required this.codeCommentColor,
    required this.codeBackground,
    required this.blockquoteColor,
    required this.blockquoteBackground,
  });

  /// 拷贝
  VanDocThemeData copyFrom({
    Brightness? brightness,
    VanCss<Color>? black,
    VanCss<Color>? white,
    VanCss<Color>? gray1,
    VanCss<Color>? gray2,
    VanCss<Color>? gray3,
    VanCss<Color>? gray4,
    VanCss<Color>? gray5,
    VanCss<Color>? gray6,
    VanCss<Color>? gray7,
    VanCss<Color>? gray8,
    VanCss<Color>? blue,
    VanCss<Color>? green,
    VanCss<Color>? purple,
    VanCss<double>? padding,
    VanCss<double>? rowMaxWidth,
    VanCss<double>? navWidth,
    VanCss<double>? borderRadius,
    VanCss<double>? simulatorWidth,
    VanCss<double>? simulatorHeight,
    VanCss<double>? headerTopHeight,
    VanCss<String>? codeFontFamily,
    VanCss<Color>? textColor1,
    VanCss<Color>? textColor2,
    VanCss<Color>? textColor3,
    VanCss<Color>? textColor4,
    VanCss<Color>? linkColor,
    VanCss<Color>? background,
    VanCss<Color>? background2,
    VanCss<Color>? background3,
    VanCss<Color>? headerBackground,
    VanCss<Color>? borderColor,
    VanCss<Color>? codeColor,
    VanCss<Color>? codeCommentColor,
    VanCss<Color>? codeBackground,
    VanCss<Color>? blockquoteColor,
    VanCss<Color>? blockquoteBackground,
  }) {
    return VanDocThemeData.raw(
      black: black ?? this.black,
      white: white ?? this.white,
      gray1: gray1 ?? this.gray1,
      gray2: gray2 ?? this.gray2,
      gray3: gray3 ?? this.gray3,
      gray4: gray4 ?? this.gray4,
      gray5: gray5 ?? this.gray5,
      gray6: gray6 ?? this.gray6,
      gray7: gray7 ?? this.gray7,
      gray8: gray8 ?? this.gray8,
      blue: blue ?? this.blue,
      green: green ?? this.green,
      purple: purple ?? this.purple,
      padding: padding ?? this.padding,
      rowMaxWidth: rowMaxWidth ?? this.rowMaxWidth,
      navWidth: navWidth ?? this.navWidth,
      borderRadius: borderRadius ?? this.borderRadius,
      simulatorWidth: simulatorWidth ?? this.simulatorWidth,
      simulatorHeight: simulatorHeight ?? this.simulatorHeight,
      headerTopHeight: headerTopHeight ?? this.headerTopHeight,
      codeFontFamily: codeFontFamily ?? this.codeFontFamily,
      brightness: brightness ?? this.brightness,
      textColor1: textColor1 ?? this.textColor1,
      textColor2: textColor2 ?? this.textColor2,
      textColor3: textColor3 ?? this.textColor3,
      textColor4: textColor4 ?? this.textColor4,
      linkColor: linkColor ?? this.linkColor,
      background: background ?? this.background,
      background2: background2 ?? this.background2,
      background3: background3 ?? this.background3,
      headerBackground: headerBackground ?? this.headerBackground,
      borderColor: borderColor ?? this.borderColor,
      codeColor: codeColor ?? this.codeColor,
      codeCommentColor: codeCommentColor ?? this.codeCommentColor,
      codeBackground: codeBackground ?? this.codeBackground,
      blockquoteColor: blockquoteColor ?? this.blockquoteColor,
      blockquoteBackground: blockquoteBackground ?? this.blockquoteBackground,
    );
  }

  /// 反序列化
  static VanDocThemeData fromJson(Brightness brightness, Map<String, dynamic> json) {
    return VanDocThemeData.raw(
      brightness: brightness,
      black: VanCss(json[kVanDocBlack.key]),
      white: VanCss(json[kVanDocWhite.key]),
      gray1: VanCss(json[kVanDocGray1.key]),
      gray2: VanCss(json[kVanDocGray2.key]),
      gray3: VanCss(json[kVanDocGray3.key]),
      gray4: VanCss(json[kVanDocGray4.key]),
      gray5: VanCss(json[kVanDocGray5.key]),
      gray6: VanCss(json[kVanDocGray6.key]),
      gray7: VanCss(json[kVanDocGray7.key]),
      gray8: VanCss(json[kVanDocGray8.key]),
      blue: VanCss(json[kVanDocBlue.key]),
      green: VanCss(json[kVanDocGreen.key]),
      purple: VanCss(json[kVanDocPurple.key]),
      padding: VanCss(json[kVanDocPadding.key]),
      rowMaxWidth: VanCss(json[kVanDocRowMaxWidth.key]),
      navWidth: VanCss(json[kVanDocNavWidth.key]),
      borderRadius: VanCss(json[kVanDocBorderRadius.key]),
      simulatorWidth: VanCss(json[kVanDocSimulatorWidth.key]),
      simulatorHeight: VanCss(json[kVanDocSimulatorHeight.key]),
      headerTopHeight: VanCss(json[kVanDocHeaderTopHeight.key]),
      codeFontFamily: VanCss(json[kVanDocCodeFontFamily.key]),
      textColor1: VanCss(json[kVanDocTextColor1.key]),
      textColor2: VanCss(json[kVanDocTextColor2.key]),
      textColor3: VanCss(json[kVanDocTextColor3.key]),
      textColor4: VanCss(json[kVanDocTextColor4.key]),
      linkColor: VanCss(json[kVanDocLinkColor.key]),
      background: VanCss(json[kVanDocBackground.key]),
      background2: VanCss(json[kVanDocBackground2.key]),
      background3: VanCss(json[kVanDocBackground3.key]),
      headerBackground: VanCss(json[kVanDocHeaderBackground.key]),
      borderColor: VanCss(json[kVanDocBorderColor.key]),
      codeColor: VanCss(json[kVanDocCodeColor.key]),
      codeCommentColor: VanCss(json[kVanDocCodeCommentColor.key]),
      codeBackground: VanCss(json[kVanDocCodeBackground.key]),
      blockquoteColor: VanCss(json[kVanDocBlockquoteColor.key]),
      blockquoteBackground: VanCss(json[kVanDocBlockquoteBackground.key]),
    );
  }
}
